using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using WB.Entity;
using WB.Entity.Helper;
using WB.Library;
namespace WB.DaoHelper
{
	public class ProductsDao : ProductsDaoBase
	{
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public static ProductsDao Instants()
		{
			return new ProductsDao();
		}

        public PagedData GetSearch(string productName, string catId, int pageCurrent)
        {
            string strSQL = "shop_SearchProduct";
            Hashtable param = new Hashtable();
            if (!string.IsNullOrEmpty(productName))
            {
                param["ProductName"] = productName;
            }

            if (!string.IsNullOrEmpty(catId))
            {
                param["CatId"] = FGuid.ToGuid(catId);
            }

            return GetPagging(strSQL, param, pageCurrent);
        }

        public ProductsEntity GetByIntId(int intId)
        {
            ProductsEntity tmp = new ProductsEntity();
            return (ProductsEntity)SelectByKey(tmp, ProductsField.IntId, intId);
        }

        public DataTable GetProductByCatId(int catId)
        {
            string strSQL = "shop_GetProductsByCatId";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@CatId", catId);
            return ExecuteDataTable(CommandType.StoredProcedure, strSQL, param);
        }

        public DataTable GetProductByCatCode(string catCode)
        {
            string strSQL = "shop_GetProductsByCatCode";
            SqlParameter[] param = new SqlParameter[1];
            param[0] = new SqlParameter("@CatCode", catCode);
            return ExecuteDataTable(CommandType.StoredProcedure, strSQL, param);
        }

	}
}
